package com.newway.common.exception;

import com.newway.common.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class GlobalException {


    @ExceptionHandler(RuntimeException.class)
    public Result<String> handleRunTimeException(RuntimeException e) {
        log.error("RuntimeException======={}",e);
        return Result.fail("系统异常：" + e.getMessage());
    }

    @ExceptionHandler(BusinessException.class)
    public Result<String> handleBusinessException(BusinessException e) {
        log.error("BusinessException======={}",e);
        return Result.fail("业务系统异常：" + e.getMessage());
    }

    @ExceptionHandler(UserInfoException.class)
    public Result<String> userInfoException(UserInfoException e) {
        log.error("UserInfoException======={}",e);
        return Result.fail(e.getCode(),"用户信息异常：" + e.getMessage());
    }
}
